package com.vagrant.code.circularsectorprogressbar;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;

import com.vagrant.code.circularsectorprogressbar.view.ChartProp;
import com.vagrant.code.circularsectorprogressbar.view.ChartView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;


public class MainActivity extends ActionBarActivity {
    ChartView mChartView;
    private ArrayList<TestBean> beanLists;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mChartView = (ChartView) this.findViewById(R.id.chartView);
        mChartView.setAntiAlias(true);
//        mChartView.setCenter(new Point(360, 240));
        mChartView.setStartAngle(0);
        mChartView.setWizardLineLength(80.0f);


        beanLists = new ArrayList<>();
        beanLists.add(new TestBean("可用余额", 10, 0xffF77F96));
        beanLists.add(new TestBean("在投本金", 30, 0xff6ED3D6));
        beanLists.add(new TestBean("投资冻结", 40, 0xffCDF0F5));
        beanLists.add(new TestBean("提现冻结", 20, 0xffFFBDCE));


        Collections.sort(beanLists, new Comparator<TestBean>() { //数字排序
            @Override
            public int compare(TestBean lhs, TestBean rhs) {
//              return (int) rhs.percent - (int) lhs.percent;//从大到小
                return (int) lhs.percent - (int) rhs.percent;//从小到大
            }
        });


        int fontSize[] = new int[]{150, 160, 170, 180};
        ArrayList<ChartProp> acps = mChartView.createCharts(beanLists.size());
        int size = acps.size();
        for (int i = 0; i < size; i++) {
            ChartProp chartProp = acps.get(i);
            chartProp.setmRlength(fontSize[i+ (4-size)]);
            chartProp.setColor(beanLists.get(i).color);
            chartProp.setPercent((beanLists.get(i).percent / 100));
            chartProp.setName(beanLists.get(i).name);
            chartProp.setFontSize(30);
        }
    }

    class TestBean implements Serializable {
        public String name;
        public float percent;
        public int color;

        public TestBean(String name, float percent, int color) {
            this.name = name;
            this.percent = percent;
            this.color = color;
        }
    }
}
